/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 jfinal app. jfapp Group.
 */

define(['adminapp'], function ($app) {
    $app.navactive('game_gift');

    var arr = ["", "礼品", "中南币"];

    var action_tpl = Handlebars.compile($(g.actiontpl).html());
    var enable_tpl = Handlebars.compile($(g.enabletpl).html());
    var nonenable_tpl = Handlebars.compile($(g.nonenabletpl).html());
    var pricute_template = Handlebars.compile($(g.pricutetemplate).html());

    $app.listtable({
        'sAjaxSource' : g.ctx + "admin/game/gift/list",
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'name' },
            {'mDataProp': 'value' },
            {'mDataProp': 'img' },
            {'mDataProp': 'status' },
            {'mDataProp': 'style' },
            {'mDataProp': 'effive_start' },
            {'mDataProp': 'effive_end' }
        ],
        'aoColumnDefs': [
            {
                'aTargets': [4],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    var img = full.img;
                    var thumbnail = img;
                    if (img) {
                        thumbnail = img.replace('.', '.thumbnail.');
                    }
                    var context = {'img' : img, 'thumbnail' : thumbnail};
                    /*if (full.img) {
                        full.img = full.img.replace('.', '.thumbnail.')
                    }*/
                    //console.log(full.img);
                    return pricute_template(context);
                }
            },
            {
                'aTargets': [5],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return full['status'] ? enable_tpl(full) : nonenable_tpl(full);
                }
            },
            {
                'aTargets': [6],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return arr[full['style']];
                }
            },
            {
                'aTargets': [9],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'data-list');
});

